package dev.spb3.model;

import jakarta.validation.Valid;
import jakarta.validation.constraints.*;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 评论实体类
 */
public class Comment {
    private Long id;  // 评论ID
    @NotBlank(message = "评论内容不能为空")
    @Size(min = 1, max = 500, message = "评论内容长度必须在1到500之间")
    private String content; // 评论内容
    @Valid
    private Movie movie; // 评论所属电影
    @NotNull(message = "评分不能为空")
    @Min(value = 1, message = "评分必须大于等于1")
    @Max(value = 5, message = "评分必须小于等于5")
    private Integer rating; // 评分

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Movie getMovie() {
        return movie;
    }

    public void setMovie(Movie movie) {
        this.movie = movie;
    }

    public Integer getRating() {
        return rating;
    }

    public void setRating(Integer rating) {
        this.rating = rating;
    }

    private static List<Comment> comments = new ArrayList<>();

    public static List<Comment> getCommentsByMovieId(Long movieId) {
        return comments.stream()
                .filter(comment -> comment.getMovie().getId().equals(movieId))
                .toList();
    }

    public static void addComment(Comment comment) {
        comment.setId((long)(comments.size() + 1));
        comments.add(comment);
    }
}

